/*
 * @Author: HaiF
 * @Date: 2020-12-23 19:52:13
 * @LastEditTime: 2021-02-09 17:01:18
 * @LastEditors: Please set LastEditors
 * @Description: 权限控制
 * @FilePath: \adminPC\src\store\modules\permission.js
 * @可以输入预定的版权声明、个性签名、空行等
 */
import { constantRoutes, asyncRouter } from '@/router'

const state = {
  routes: [],
  addRoutes: []
}

const mutations = {
  SET_ROUTES: (state, routes) => {
    state.addRoutes = routes
    state.routes = constantRoutes.concat(routes)
  }
}

const actions = {
  generateRoutes({ commit }, roles) {
    return new Promise(resolve => {
      let accessedRoutes
      // TODO: 权限判断
      if (0 && roles.includes('1')) {
        accessedRoutes = asyncRouter || []
      } else {
        accessedRoutes = asyncRouter(roles)
      }
      commit('SET_ROUTES', accessedRoutes)
      resolve(accessedRoutes)
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

